package com.life.notes.service.impl;

import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.life.notes.dao.SysLogMapper;
import com.life.notes.dto.LogQueryPara;
import com.life.notes.model.SysLog;
import com.life.notes.service.SysLogService;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;


/**
 * <p> 系统管理 - 日志表 服务实现类 </p>
 *
 * @author: zhengqing
 * @date: 2019-09-18 10:51:57
 */
@Service
@Transactional
public class SysLogServiceImpl extends ServiceImpl<SysLogMapper, SysLog> implements SysLogService {

    @Override
    public IPage<SysLog> listPage(LogQueryPara para) {
        Page<SysLog> page = new Page<>(para.getPage(),para.getLimit());
        IPage<SysLog> result = this.baseMapper.selectLogs(page, para);
        result.getRecords().forEach( e->{
            if (e.getUserId()==0){
                e.setUsername("非法人员");
            }
        });
        return result;
    }

    @Override
    public List<SysLog> list(LogQueryPara para) {
        return this.baseMapper.selectLogs(para);
    }

    @Override
    public Integer saveLog(SysLog para) {
        if (para.getId()!=null) {
            this.baseMapper.updateById(para);
        } else {
            this.baseMapper.insert(para);
        }
        return para.getId();
    }

}
